﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GameNode
{
    class Drawer
    {
        public int height { get; private set; }
        public int width { get; private set; }
        public int X { get; private set; }
        public int Y { get; private set; }


        public void DrawBorder(int borderWidth, int borderHeight, int x, int y, char borderSymbol, ConsoleColor color)
        {
            height = borderHeight;
            width = borderWidth;
            X = x;
            Y = y;

            Console.ForegroundColor = color;

            for (int i = 0; i < borderHeight; i++)
            {
                for (int j = 0; j < borderWidth; j++)
                {
                    if (i == 0 || i == borderHeight - 1)
                    {
                        Console.Write(borderSymbol);
                    }
                    else if (j == 0 || j == borderWidth - 1)
                    {
                        Console.Write(borderSymbol);
                    }
                    else
                    {
                        Console.Write(' ');
                    }
                }
                Console.WriteLine();
            }
            Console.MoveBufferArea(0, 0, borderWidth, borderHeight, x, y);
        }

        public void DrawNode(Node node)
        {
            Console.SetCursorPosition(node.X, node.Y);
            Console.ForegroundColor = node.Color;
            Console.Write(node.NodeSymbol);
        }

        public void ClearNode(Node node)
        {
            Console.SetCursorPosition(node.X, node.Y);
            Console.Write(' ');
        }

        public void DrawWinnerNodesAndMessage(List<Node> nodes, int shift, string message)
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.SetCursorPosition(X + width + shift, Y);
            Console.Write(message);

            int nodeCounter = 0;
            foreach (var node in nodes)
            {
                Console.ForegroundColor = node.Color;
                Console.SetCursorPosition(X + width + shift + 2, Y + nodeCounter + 1);
                Console.Write(node.NodeSymbol);
                nodeCounter++;
            }
        }

        public void DrawLooserNodesAndMessage(List<Node> nodes, int shift, string message)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(X + width + shift, Y);
            Console.Write(message);

            int nodeCounter = 0;
            foreach (var node in nodes)
            {
                Console.ForegroundColor = node.Color;
                Console.SetCursorPosition(X + width + shift + 3, Y + nodeCounter + 1);
                Console.Write(node.NodeSymbol);
                nodeCounter++;
            }
        }
    }
}
